﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EarringsRecommendationWeb
{
    public partial class index2 : CheckUserSession
    {
        private MemberEarrings _memEarrings = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);

            Member mem = Session["member"] as Member;

            if (mem != null)
            {
                Response.Write("<input id='hidden-email' type='hidden' value='" + mem.Email + "'>");
                Response.Write("<input id='hidden-name' type='hidden' value='" + mem.Name + "'>");
            }

            //Check Post Method 
            if (!IsPostBack)
            {
                string personId = Session["personalId"].ToString();
                if (!string.IsNullOrEmpty(personId))
                {
                    _memEarrings = new MemberEarrings();
                    _memEarrings = GlobalFunction.GetMemberEarrings(personId);
                    //For Auto radio Selection if it has data in db.
                    ClientScript.RegisterArrayDeclaration("PersonInfo", JsonConvert.SerializeObject(_memEarrings));

                    Session["personalid"] = personId;
                }
                //Session["faceShape"] = Request["faceshape"];
                //Session["neck"] = Request["neck"];
                //Session["personalid"] = Request["personalid"];
                //Session["rightearlobeposition"] = Request["rightearlobeposition"];
                //Session["leftearlobeposition"] = Request["leftearlobeposition"];
                //Session["cdwidth"] = Request["cdwidth"];
            }            
    }

        protected void NextStep3(object sender, EventArgs e)
        {
            string earlobe = Request.Form["rdoTing"];
            string earshape = Request.Form["rdoBaihu"];
            string hairstyle = Request.Form["rdoHairStyle"];
            string skincolor = Request.Form["rdoSkincolor"];

            string personId = Session["personalId"].ToString();

            var values = new NameValueCollection();
            values["personalid"] = personId;
            //values["faceshape"] = _memEarrings.FaceShape; //Session["faceShape"].ToString();
            //values["neck"] = _memEarrings.Neck; //Session["neck"].ToString();           
            //values["rightearlobeposition"] = _memEarrings.REarlobePosition; //Session["rightearlobeposition"].ToString();
            //values["leftearlobeposition"] = _memEarrings.LEarlobePosition; //Session["leftearlobeposition"].ToString();
            //values["earlobe"] = earlobe;
            //values["earshape"] = earshape;
            //values["hairstyle"] = hairstyle;
            //values["skincolor"] = skincolor;

            //Update MemberEarrings
            GlobalFunction.UpdateMemberEarrings(personId, earlobe, earshape, hairstyle, skincolor);

            WebExtensions.RedirectWithData(values, "index3.aspx");

        }
    }
}